import {
  Component, inject, input, OnInit
} from '@angular/core';
import {UsersService} from '../users.service';
import {
  ActivatedRoute,
  ActivatedRouteSnapshot,
  ResolveFn,
  RouterLink,
  RouterOutlet, RouterStateSnapshot
} from '@angular/router';

@Component({
  selector: 'app-user-tasks',
  imports: [
    RouterOutlet,
    RouterLink
  ],
  templateUrl: './user-tasks.html',
  styleUrl: './user-tasks.css'
})
export class UserTasks{
  userName= input.required<string>();
  message = input.required<string>();

  // private activatedRoute = inject(ActivatedRoute);
  //
  // ngOnInit():void{
  //   this.activatedRoute.data.subscribe({
  //     next:data=>{
  //       console.log(data);
  //     }
  //   })
  // }
}

export const resolveUserName:ResolveFn<string> =(activatedRoute:ActivatedRouteSnapshot,routerState:RouterStateSnapshot)=>{
  const usersService = inject(UsersService);
  const userName = usersService.users.find(
    (u) => u.id === activatedRoute.paramMap.get('userId')
  )?.name || '';

  return userName;
};
